package com.paohe.lianxin_pda;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;
import com.paohe.lianxin_pda.production_line.chengpPei.ChengPei;
import com.paohe.lianxin_pda.production_line.picking.Picking;
import com.paohe.lianxin_pda.utils.toast.CustomToast;
import com.wang.avi.AVLoadingIndicatorView;
import com.zyao89.view.zloading.ZLoadingDialog;

import static com.zyao89.view.zloading.Z_TYPE.CIRCLE;
import static com.zyao89.view.zloading.Z_TYPE.ELASTIC_BALL;
import static com.zyao89.view.zloading.Z_TYPE.INTERTWINE;
import static com.zyao89.view.zloading.Z_TYPE.PAC_MAN;
import static com.zyao89.view.zloading.Z_TYPE.SNAKE_CIRCLE;
import static com.zyao89.view.zloading.Z_TYPE.STAR_LOADING;

public class IndexActivity extends Activity {


    private ImageView back;//返回
    private TextView title;//标题名称
    private LinearLayout block1,block2,block3,block4, block5, block6;
    private TextView popTxt1,popTxt2,popTxt3;
    //加载框Loading
    private ZLoadingDialog zLoadingDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);

        back = findViewById(R.id.back);
        title = findViewById(R.id.title_name);
        block1 = findViewById(R.id.index_block1);
        block2 = findViewById(R.id.index_block2);
        block3 = findViewById(R.id.index_block3);
        block4 = findViewById(R.id.index_block4);
        block5 = findViewById(R.id.index_block5);
        block6 = findViewById(R.id.index_block6);

        zLoadingDialog = new ZLoadingDialog(IndexActivity.this);

        //给标签赋值
        title.setText(R.string.index_home);

        //返回按钮
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //各模块之间的跳转
        block1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳出弹窗
                final View contentView = LayoutInflater.from(IndexActivity.this).inflate(R.layout.pop_choose_material,null,false);
                popTxt1 = contentView.findViewById(R.id.pop_txt1);
                popTxt2 = contentView.findViewById(R.id.pop_txt2);
                popTxt3 = contentView.findViewById(R.id.pop_txt3);
                //填充视图、宽度、高度、是否能获得焦点
                final PopupWindow pop = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, 800,true);
                //设置背景
                pop.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                // 设置PopupWindow是否能响应外部点击事件
                pop.setOutsideTouchable(true);
                // 设置PopupWindow是否能响应点击事件
                pop.setTouchable(true);
                //动画
                pop.setAnimationStyle(R.style.PopAnimTranslate);
                pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        WindowManager.LayoutParams lp = getWindow().getAttributes();
                        lp.alpha = 1.0f;
                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                        getWindow().setAttributes(lp);
                    }
                });
                pop.showAtLocation(contentView, Gravity.BOTTOM,0,0);
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 0.3f;
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                getWindow().setAttributes(lp);

                //弹窗的点击事件
                popTxt1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CustomToast.showToast(IndexActivity.this,"暂无SAR原料!");
                    }
                });
                popTxt2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        zLoadingDialog.setLoadingBuilder(CIRCLE).setLoadingColor(Color.BLACK).setHintText("Loading...").show();
                        Intent intent = new Intent(IndexActivity.this, ChengPei.class);
                        startActivity(intent);
                        pop.dismiss();

                    }
                });
                popTxt3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        CustomToast.showToast(IndexActivity.this,"暂无SAR制剂!");
                    }
                });

            }
        });

        //包装管理
        block2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(IndexActivity.this, Picking.class);
                startActivity(intent);
            }
        });

        //仓库管理
        block3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CustomToast.showToast(IndexActivity.this,"模块3!");
            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
        //关闭Loading弹窗
        zLoadingDialog.dismiss();
    }
}
